import os
from google.appengine.ext.webapp import template

from google.appengine.ext import webapp

from models.Topics import *
from models.Groups import *
from models.Audit import *
from models.Authentication import *
from google.appengine.api import images


class CustomizeProfile(webapp.RequestHandler):
    def get(self,userID):
        user= User.get_by_id(int(userID))        

        template_values = {"user":user}
        path = os.path.join(os.path.dirname(__file__),"../templates/CustomizeProfile.html")
        self.response.out.write(template.render(path,template_values))
    def post(self,userID):
        user = get_current_user(self.request) 
        user.displayname = self.request.get('displayname')
        if(self.request.get('avatar')):
            #avatar = images.resize(self.request.get('avatar'),32,32)
            avatar = self.request.get('avatar')
            user.avatar = db.Blob(avatar)
        user.aboutMe = self.request.get('aboutMe')
        user.website = self.request.get('website')
        user.put()
        
        self.redirect('/group')
        
class ViewProfile(webapp.RequestHandler):
    def get(self,userID):
        user = User.get_by_id(int(userID))

        template_values = {"user":user}
        path = os.path.join(os.path.dirname(__file__),"../templates/ViewProfile.html")
        self.response.out.write(template.render(path,template_values))



